<? 
	include('base.php');
	User::protect();
	$page_title = 'Band Member Diaries';
	include_class('band_diaries');
	include_class('band_members');

	if ($_GET['memberID']) {
		$bm = BandMember::get($_GET['memberID']);
		$bdlist = $bm->getDiaries($_GET['entries_per_page'], $_GET['start']);
		$news_total = $bm->getTotalDiaryEntries();
		
		 if (!db::isError($bm)) { 
			$uo = $bm->getUserObject();
			$uoc = User::getCurrent();
		 }
	}
	$section = 'band_diaries';
	include('layout/header.php');


if (is_object($bm) && !db::isError($bm)) {
 ?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php">Diaries&nbsp;&#62;</a>&nbsp;<?=$uo->getFirstName()?>'s Diary
</div>

	<h1><?=strtolower($uo->getFirstName())?>'s diary:</h1>
	<div class="inset">
	<p>
	<form id="amount_form" action="<?=$PHP_SELF?>" method="get">
		<? if (User::isAdmin() || ($uoc->getID() == $uo->getID())) { ?><a href="band_diary_add.php?memberID=<?=$_GET['memberID']?>">Add Diary Entry</a><span class="padded">|</span><? } ?>
		<? include('layout/paging.php'); ?>
	</form>
	</p>
	<p>
	<table class="list" border="0" cellspacing="1" cellpadding="0">
	<tr>
		<td class="header" colspan="2">Date/Time</td>
		<td class="header">Title</td>
	</tr>
	<?
		if (is_array($bdlist) && count($bdlist) > 0) { 
		foreach ($bdlist as $bd) { ?>
		<tr>
			<td><?=$bd->getDate()?></td>
			<td><?=$bd->getTime()?></td>
			<td valign="top" width="70%"><a href="band_diary_edit.php?id=<?=$bd->getID()?>"><?=$bd->getTitle()?></a><? if (!$bd->isActive()) { ?> <img src="images/inactive.gif" alt="Entry is Inactive" width="10" height="10" title="Entry is Inactive"><? } ?></td>
		</tr>				
		<? }
		} else {?>
		<tr>
			<td colspan="3">No entries</td>
		</tr>
	<? } ?>
	</table>
	</p>		
	</div>

<? } else { ?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;Diaries
</div>


	<h1>band diaries:</h1>
	<div class="inset">
	<?
		$band = new BandMemberList();
		$bandlist = $band->get_band_members();
	?>
	<?
		foreach ($bandlist as $bm) {
			$total = $bm->getTotalDiaryEntries();
			$uo = $bm->getUserObject();
			?>
		<p>
			<a href="band_diaries.php?memberID=<?=$bm->getID()?>"><?=$uo->getFirstName()?>'s Diary</a><br/>
			Total Entries: <strong><?=$total?></strong>
			<? if ($total > 0) {
				$bdo = $bm->getLatestDiaryObject(); ?>
				<span class="padded">|</span>
				Latest Entry: <?=$bdo->getTitle()?>
			<? } ?>
		</p>				
		<? }
	
	?>
	</div>


<? } ?>

<? include('layout/footer.php'); ?>
